﻿Imports System.Drawing

'<Serializable()> Public Enum ShapeDescEnum
'    Circle
'    Polyline
'    Square
'    Line
'    PLine
'    Point
'    Rectangle



'End Enum



<Serializable()> Public MustInherit Class BaseTool

    'Dim m_ShapeDesc As ShapeDescEnum = ShapeDescEnum.Polyline




    '这里是因为画圆很不方便临时做的实验

    <NonSerialized()> Public mapwin As AxMapWinGIS.AxMap


    '这个函数已经上升为必须调用的函数
    Public Sub SetMapRef(ByRef m As AxMapWinGIS.AxMap)
        mapwin = m

    End Sub



    Public Event endDrawing(ByVal d As Double)

    Public lColor As Drawing.Color = Color.Pink




    Private operShape As BaseShape = Nothing
    Public Property OperShapeProperty() As BaseShape
        Get
            Return operShape
        End Get
        Set(ByVal value As BaseShape)
            operShape = value
        End Set
    End Property
    Private upPoint As New Drawing.Point
    Public Property UpPointProperty() As Drawing.Point
        Get
            Return upPoint
        End Get
        Set(ByVal value As Drawing.Point)
            upPoint = value
        End Set
    End Property
    Private downPoint As New Drawing.Point
    Public Property DownPointProperty() As Drawing.Point
        Get
            Return downPoint
        End Get
        Set(ByVal value As Drawing.Point)
            downPoint = value
        End Set
    End Property
    Private newmovepoint As New Drawing.Point
    Public Property NewmovepointProperty() As Drawing.Point
        Get
            Return newmovepoint
        End Get
        Set(ByVal value As Drawing.Point)
            newmovepoint = value
        End Set
    End Property
    Private oldmovepoint As New Drawing.Point
    Public Property OldmovepointProperty() As Drawing.Point
        Get
            Return oldmovepoint
        End Get
        Set(ByVal value As Drawing.Point)
            oldmovepoint = value
        End Set
    End Property
    Private newdragpoint As New Drawing.Point
    Public Property NewdragpointProperty() As Drawing.Point
        Get
            Return newdragpoint
        End Get
        Set(ByVal value As Drawing.Point)
            newdragpoint = value
        End Set
    End Property
    Private olddragpoint As New Drawing.Point
    Public Property OlddragpointProperty() As Drawing.Point
        Get
            Return olddragpoint
        End Get
        Set(ByVal value As Drawing.Point)
            olddragpoint = value
        End Set
    End Property





    '关于要继承的抽象方法
    Public MustOverride Sub mouseUp(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_MouseUpEvent)
    Public MustOverride Sub mouseDown(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_MouseDownEvent)
    Public MustOverride Sub mouseMove(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_MouseMoveEvent)
    Public MustOverride Sub mouseDrag(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_MouseMoveEvent)
    Public MustOverride Sub mouseDblClick(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Public MustOverride Sub setself()
    Public MustOverride Sub unSet()

    '父类的消息分发

    Public Sub superMouseUp(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_MouseUpEvent)

        Me.upPoint = New Point(e.x, e.y)
        Me.mouseUp(sender, e)



    End Sub

    Public Sub superMouseDown(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_MouseDownEvent)


        Me.downPoint = New Point(e.x, e.y)
        Me.newmovepoint = New Point(e.x, e.y)
        Me.oldmovepoint = New Point(e.x, e.y)

        Me.newdragpoint = New Point(e.x, e.y)
        Me.olddragpoint = New Point(e.x, e.y)


        Me.mouseDown(sender, e)

    End Sub

    Public Sub superMouseMove(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_MouseMoveEvent)

        Me.newmovepoint = New Point(e.x, e.y)

        Me.mouseMove(sender, e)

        '更新坐标系统
        Me.oldmovepoint = New Point(e.x, e.y)

    End Sub


    Public Sub superMouseDrag(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_MouseMoveEvent)

        Me.newdragpoint = New Point(e.x, e.y)

        Me.mouseDrag(sender, e)

        Me.olddragpoint = New Point(e.x, e.y)


    End Sub

    Public Sub superMouseDblClick(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Me.mouseDblClick(sender, e)



    End Sub



    '取得屏幕坐标
    Public Function getScreen(ByVal ptf As Drawing.PointF) As Drawing.Point

        Dim pt As New Drawing.Point

        pt.X = ptf.X
        pt.Y = ptf.Y



        Return mapwin.PointToScreen(pt)

    End Function

    '触发绘画完成事件
    Public Sub InvokeEndDrawing()

        RaiseEvent endDrawing(1)

    End Sub

    Public Overridable Sub CancelDraw()

        Me.OperShapeProperty = Nothing


    End Sub

    '用于确定是否处于绘制状态
    Public Function IsOnDrawing() As Boolean

        If Me.OperShapeProperty Is Nothing Then
            Return False
        Else
            Return True
        End If

    End Function




End Class
